<template>
  <div class="wrap">    
    <div class="tab">
      <ul class="tab-top">
        <li @click="type = '00'" :class="{'active': type === '00'}">
          全部
        </li>
        <li @click="type = '01'" :class="{'active': type === '01'}">
          已完成
        </li>
        <li @click="type = '02'" :class="{'active': type === '02'}">
          可提现
        </li>
        <li @click="type = '03'" :class="{'active': type === '03'}">
          待收货
        </li>
      </ul>
    </div>
    <div class="flex tab-total">
      <div>
        <p>订单数</p>
        <p>{{tableData.length}}</p>
      </div>
      <div>
        <p>付款金额</p>
        <p>￥{{payTotal}}</p>
      </div>
      <div>
        <p>预估收入</p>
        <p>￥{{fanyongTotal}}</p>
      </div>
    </div>
    <div class="tab-ct">
      <div v-if="type === '00'">全部1</div>
      <div v-if="type === '01'">已完成1</div>
      <div v-if="type === '02'">可提现1</div>
      <div v-if="type === '03'">待收货1</div>
      <ul>
        <li v-for="(item, index) in tableData" :key="index">
          <div>
            <div class="imgWrap"></div>
            <div class="textWrap">
              <div class="flex">
                <span :class="['bg-icon', item.is_jiesuan==='1'?'bg-icon-green':'bg-icon-blue']">{{item.status}}</span>
                <p>付款金额: {{item.pay}}</p>
              </div>
              <div>
                <h4>{{item.title}}</h4>
              </div>
            </div>
          </div>
          <div class="flex">
            <div class="gray">
              <p>{{item.fukuan_time}}付款</p>
            </div>
            <p>预估收入: <span class="bold">{{item.fanyong}}</span></p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { formatTime } from '@/utils/index'
import card from '@/components/card'
// import * as axios from 'axios'

export default {
  components: {
    card
  },

  data () {
    return {
      payTotal: 0,
      fanyongTotal: 0,
      type: '00',
      tableData: [{
        dingjing: '0.00',
        fanyong: '4.55',
        fukuan_time: '2019-10-07T16:00:00.000Z',
        id: 263,
        is_jiesuan: '1',
        no: '560139364436349091',
        pay: '42.90',
        percent: '20.00%',
        price: 0.1,
        status: '已结算',
        title: '【超值价】拉面说广式胡椒猪肚鸡方便速食非油炸拉面三盒装拉面',
        yg_souru: '8.58'
      }, {
        dingjing: '0.00',
        fanyong: '4.55',
        fukuan_time: '2019-10-07T16:00:00.000Z',
        id: 263,
        is_jiesuan: '1',
        no: '560139364436349091',
        pay: '42.90',
        percent: '20.00%',
        price: 0.1,
        status: '已结算',
        title: '【超值价】拉面说广式胡椒猪肚鸡方便速食非油炸拉面三盒装拉面',
        yg_souru: '8.58'
      }]
    }
  },
  filters: {
    formatTime (v) {
      return formatTime(new Date(v), 'yyyy年MM月dd日')
    }
  },
  mounted () {
    // this.getOrderList()
    this.payCount()
    this.fanyongFn()
  },
  methods: {
    /**
     * 获取当前订单信息
     * @Author   chend
     * @DateTime 2019-10-22T18:35:41+0800
     */
    getOrderList () {
    //   console.log('getOrderList')
    //   axios({
    //     method: 'post',
    //     url: 'http://www.ilove03.com/api/getOrderList',
    //     responseType: 'json',
    //     data: {}
    //   }).then(response => {
    //     console.log(response, 'success')
    //   }).catch(e => {
    //   })
      this.$http.getOrderList().then(res => {
        this.tableData = res.result.reverse()
        console.log('tableData', this.tableData)
      })
    },
    /**
     * 总付款金额
     */
    payCount () {
      let list = this.tableData
      let pay = 0
      if (list.length > 0) {
        list.forEach((e, j) => {
          if (e.pay) {
            pay += parseFloat(e.pay)
          }
        })
      }
      this.payTotal = pay
    },
    /**
     * 总返利
     */
    fanyongFn () {
      let list = this.tableData
      let fanyong = 0
      if (list.length > 0) {
        list.forEach((e, j) => {
          if (e.fanyong) {
            fanyong += parseFloat(e.fanyong)
          }
        })
      }
      this.fanyongTotal = fanyong.toFixed(2)
    }
  }
}
</script>

<style>
.wrap{
  background: #eee;
} 
.flex{
  display: flex;
  justify-content: space-between;
}
.flex p{
  line-height: 30px;
}
.tab-total{
  padding: 10px;
  margin-bottom: 5px;
  background: #fff;
}
.tab{
  padding: 10px;
  margin-bottom: 5px;
  background: #fff;
}
.tab-top {
  display: flex;
  justify-content: space-between;
}
.tab-top .active{
  border-bottom: 2px solid #075db3;
}
.tab-ct{
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  background: #fff;
  box-sizing: border-box;
  font-size: 14px;
  text-align: left;
}
.tab-ct ul li{
  position: relative;
  padding: 5px;
  border-bottom: 1px solid #eee;
}
.tab-ct ul li h4{
  /* padding-right: 90px; */
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
  line-height: 38px;
  color: #555;
}

.gray{
  color: #777;
}
.imgWrap{
  position: absolute;
  left: 0px;
  top: 10px;
  width: 60px;
  height: 60px;
  background: navajowhite;
  border-radius: 5px;
}
.textWrap{
  padding-left: 60px;
  box-sizing:border-box;
}
.bg-icon{
  /* position: absolute;
  top: 5px;
  right: 0; */
  width: 70px;
  margin-left: 20px;
  line-height: 25px;
  height: 25px;
  text-align: center;
  border-radius: 10px;
  color: #fff;
}
.bg-icon-blue{
  background: #0090ff;
}
.bg-icon-green{
  background: #00ba79;
}
.bold{
  font-weight: bold;
  color: #111;
}

.radio {
    display: inline-block;
    position: relative;
    width: 67px;
}
 
.radio input[type="radio"] {
    position: absolute;
    width: 0;
    height: 0;
}
 
.radio input[type="radio"]:after {
    content:'';
    /* background-image: url(/img/archive/radio.png); */
    background-size:20px 20px;
    width:20px;
    height:20px;
    position: absolute;
    z-index: 100;
    left: 30px;
    top: -4px;
}
 
.radio input[type="radio"]:checked:after {
    /* background-image: url(/img/archive/radioActive.png); */
    background-size:18px 18px;
    width:18px;
    height:18px;
}

</style>
